<template>
    <div>
        <!-- 地址添加页面顶部导航区域 -->
        <nav-comp :back="true" title="添加收货地址"></nav-comp>
        <gap-comp :height="1"></gap-comp>
        <!-- 地址表单区域  -->
        <van-address-edit :area-list="areaList" show-set-default :area-columns-placeholder="['请选择', '请选择', '请选择']"
            @save="onSave" />
    </div>
</template>

<script>
// 引入省市区地址数据
import { areaList } from '@vant/area-data';
export default {
    data() {
        return {
            areaList,//省市区联动数据
            uid: this.$utils.getUid()//用户的uid
        };
    },
    methods: {
        // 1.提交地址数据
        onSave(info) {
            // 1.获取提交数据
            let insertData = {}
            insertData.uid = this.uid
            insertData.username = info.name
            insertData.userphone = info.tel
            insertData.location = info.province + info.city + info.county
            insertData.useraddress = info.addressDetail
            insertData.status = info.isDefault ? 1 : 0
            // console.log(insertData)
            // 2.验证提交数据
            // 3.执行提价操作
            this.$api.reqAddressAdd(insertData)
                .then(res => {
                    console.log(res)
                    this.$notify({
                        type: 'success',
                        message: '添加成功！'
                    });
                })
                .catch(err => console.log(err))
        },
        // 2.删除表单中的地址数据
        onDelete() { }
    },
};
</script>

<style scoped></style>
